import request from '@/utils/request'
import store from '@/store'

// 添加知识
export function addKnowledge(params) {
    return request({
        method: 'post',
        url: 'knowledges/addKnowledge',
        data: params,
    })
}

// 分页查询所有知识
export function selectKnowledgesPage(params) {
    return request({
        method: 'get',
        url: 'knowledges/all',
        params: params,
    })
}

//根据id修改知识
export function updateKnowledgeById(params) {
    return request({
        method: 'put',
        url: 'knowledges/updateKnowledge',
        data: params,
    })
}

// 根据id删除知识
export function deleteKnowledgeById(params) {
    return request({
        method: 'delete',
        url: 'knowledges/deleteKnowledge/' + params.knowledgeId,
    })
}

// 根据id查询知识信息
export function selectKnowledgeById(params) {
    return request({
        method: 'get',
        url: 'knowledges/selectKnowledgeById/' + params.knowledgeId,
    })
}

// 根据登录用户查询知识 
export function selectKnowledgeByUsername() {
    return request({
        method: 'get',
        url: 'knowledges/selectByUser',
    })
}

// 根据登录用户查询知识评论
export function selectComment(params) {
    return request({
        method: 'get',
        url: `/knowledges/selectDiscuss/${params.knowledgeId}`,
    })
}

// 增加评论
export function addComment(params) {
    return request({
        method: 'post',
        url: `knowledges/addDiscuss/${params.knowledgeId}`,
        params: {
            content: params.content
        },
    })
}